package cn.fudan.pms.dao;

import cn.fudan.pms.domain.bo.IssueBO;
import cn.fudan.pms.domain.po.Issue;
import cn.fudan.pms.domain.po.IssueExample;
import cn.fudan.pms.domain.po.IssueRecordExample;
import cn.fudan.pms.mbg.mapper.IssueMapper;
import cn.fudan.pms.mbg.mapper.IssueRecordMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class IssueDao {
    @Autowired
    private IssueMapper issueMapper;
    @Autowired
    private IssueRecordMapper issueRecordMapper;

    public IssueBO getIssueByUuid(String uuid) {
        IssueExample issueExample = new IssueExample();
        issueExample.createCriteria().andUuidEqualTo(uuid);
        List<Issue> issueList = issueMapper.selectByExample(issueExample);
        IssueBO ret = new IssueBO();
        BeanUtils.copyProperties(issueList.get(0), ret);
        IssueRecordExample issueRecordExample = new IssueRecordExample();
        issueRecordExample.createCriteria().andIssueUuidEqualTo(uuid);
        ret.setRecords(issueRecordMapper.selectByExample(issueRecordExample));
        return ret;
    }
}
